package com.erp.erp_project.controller;

import com.erp.erp_project.core.AjaxResult;
import com.erp.erp_project.core.annotation.Permission;
import com.erp.erp_project.model.Work;
import com.erp.erp_project.service.WorkService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Controller
@AllArgsConstructor
@RequestMapping("/ueditor/html")
public class Editor {
    private final WorkService workService;

    @GetMapping("/test")
    @Permission("作业修改")
    public String editor(Work work,Model model){
        model.addAttribute("work",workService.selectById(work.getId()));
        Work work1=workService.selectById(work.getId());
        System.out.println(work1);
        return "ueditor/html/test";
    }

//    @RequestMapping("edit")
//    public String edit(Work work, Model model) {
//        model.addAttribute("work",workService.selectById(work.getId()));
//        return "work/edit";
//    }
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult<String> edit(Work work) {
        workService.update(work);
        return new AjaxResult<String>("修改成功");
    }

    @PostMapping("/upload")
    @ResponseBody
    public void ueditor(String fd) {
        System.out.println(fd);
        System.out.println("进来了");
    }
}
